<template>
  <div class="app-container">
    <query @updateData="updateData"></query>

    <el-table
      :data="loanData"
      border
      fit
      highlight-current-row
      style="width: 100%"
      sort-change="dateSort"
    >
      <el-table-column
        align="center"
        sortable="custom"
        :prop="loanData.createdTime"
        :label="loanRemark.createdTime"
        width="200"
      >
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.createdTime }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="totalMoney"
        :label="loanRemark.totalMoney"
        width="120"
      >
      </el-table-column>
      <el-table-column
        prop="paidMoney"
        :label="loanRemark.paidMoney"
        width="120"
      >
      </el-table-column>
      <el-table-column
        prop="interestRate"
        :label="loanRemark.interestRate"
        width="120"
      >
      </el-table-column>
      <el-table-column :label="loanRemark.type" min-width="150px">
        <template #default="{ row }">
          <el-tag>{{ row.type }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column :label="loanRemark.status" min-width="150px">
        <template #default="{ row }">
          <el-tag>{{ row.status }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        :label="loanRemark.operation"
        align="center"
        width="230"
        class-name="fixed-width"
      >
        <template #default="{ row }">
          <el-button type="primary" size="mini" @click="handleSeekInfo()">
            {{ loanRemark.seek }}
          </el-button>
          <el-button size="mini" type="danger" @click="delLoan(row.id)">
            {{ loanRemark.danger }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="pageData.total"
      v-show="pageData.total > 0"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageData.currentPage"
      :page-sizes="[10, 20, 50, 100]"
      layout="total, sizes, prev, pager, next, jumper"
    />
  </div>
</template>

<script>
import query from "./query/index.vue";

export default {
  components: {
    query,
  },
  data() {
    return {
      loanRemark: {
        id: "ID",
        borrowId: "借款人ID",
        approverId: "贷款人ID",
        status: "状态",
        type: "贷款类型",
        totalMoney: "总额",
        paidMoney: "已还款额度",
        interestRate: "利率",
        createdTime: "贷款时间",
        operation: "操作",
        seek: "查看信息",
        edit: "编辑",
        danger: "删除",
      },
      loanData: [],
      pageData: {
        total: 10,
        page: 1,
        limit: 10,
        currentPage: 1,
      },
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      this.$store
        .dispatch("request/get", "/basic/loan/query/list")
        .then((data) => {
          this.loanData = data;
        });
    },
    getSortClass(key) {
      console.log(key + "***");
    },
    sortChange(data) {
      const { prop, order } = data;
      if (prop === "id") {
        dataMap.sortByID(order);
      }
    },
    handleSeekInfo() {
      this.dialogueRemark.isVisible = true;
    },
    handleDelete() {},
    handleCurrentChange(page) {
      console.log(page);
    },
    handleSizeChange(val) {
      console.log(val);
    },
    handleAdd() {
      this.dialogueRemark.isVisible = true;
    },
    updateData() {
      this.getData();
    },
    dateSort() {},
    delLoan(loanId) {
      let data = {
        loanId: loanId,
        url: "/basic/loan/del",
      };
      this.$store.dispatch("request/getP", data).then(() => {
        this.$message.success("删除成功！！");
        this.getData();
      });
    },
  },
};
</script>